<?php 
namespace town\model;

use town\dmod\DB;
use town\dmod\Model;

class Comment extends Model
{
	public $tableName = 'comments';


	/**
	 * 更具postID获取评论列表
	 */
	public function commentsByPostId($pid)
	{
		$list = DB::table('com_map_posts')->where('pid', $pid)->lists('cid');
		if (empty($list)) {
			return [];
		}
		$id_arr = [];
		foreach ($list as $key => $value) {
			$id_arr[] = $value['cid'];
		}
		$list = DB::table($this->tableName)->where('id', ['in', $id_arr])->get();
		if (is_array($list)) {
			foreach ($list as $key => &$value) {
				$value['create_at'] = date('Y/m/d', $value['create_at']);
			}
		}
		return $list;
	}
}